<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>关闭广告</title>
    <style>
        .ad{
            width: 400px;
            height: 400px;
            background-color: aqua;
            margin: auto;
            margin-top: 15px;
        }
        .ad .close{
            position: absolute;/*相对定位*/
            top: -5px;
            right: 258px;
            float: right;
            width: 8px;
            height: 12px;
            border: 2px solid red;
            font-size: 10px;
        }
    </style>
</head>
<body>
    <div class="ad1">1</div>
    <div class="ad">2
    <h3 class="close">X</h3>
    <h3 class="close2">Y</h3>
    <h3 class="close3">Z</h3>
</div>
    <script>
        const clos=document.querySelector('.close');
        clos.addEventListener('click',function(){
            //事件处理函数
            // const ad=document.querySelector('.ad');
            clos.parentElement.style.display='none';
        },false);
        //const ad=document.querySelector('.ad')
        console.log(clos.parentNode);
        console.log(clos.parentElement);

        const ad=document.querySelectorAll('.ad');
        console.log(ad[0].childNodes);
        console.log(ad[0].children);

        // console.log(ad[1].childNodes);
        // console.log(ad[1].children);

        // const clo2=document.querySelector('.close');
        // console.log(clo2.previousElementSibling);
        const a1=document.querySelector('.ad1');
        // const son=nextElementSibling.children;
        console.log(a1.nextElementSibling.children);
        // console.log(son[0]);
    </script>


    <div class="fat">5</div>
    <button>节点</button>
    <script>
        const btn=document.querySelector('button');
        btn.addEventListener('click',function(){
            //点击按钮创建节点并显示到网页中
            const box=document.createElement('div');
            box.innerHTML='这是新创建的box';
            //向它的哥哥追加一个div(box)
            btn.previousElementSibling.appendChild(box);
            
        })
    </script>
</body>
</html>